<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Async-Promise</title>
    <script src="http://code.jquery.com/jquery-3.3.1.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
    $(function () {
        // $.get("", function (data, status) {
        //     if (status == 'success') {
        //         $.get("", function (data, status) {
        //             if (status == 'success') {
        //                 $.get("", function (data, status) {
        //                     console.log(data);
        //                 });
        //             }
        //         });
        //     }
        // });

        // new Promise(function (resolve, reject) {
        //     $.get("", function (data, status) {
        //         if (status == 'success') {
        //             resolve("P01 Success");
        //         } else {
        //             reject("P01 Fail")
        //         }
        //     });
        // }).then(function (data) {
        //     return new Promise(function (resolve, reject) {
        //         $.get("", function (data, status) {
        //             if (status == 'success') {
        //                 resolve("P02 Success");
        //             } else {
        //                 reject("P02 Fail")
        //             }
        //         });
        //     });
        // }).then(function (data) {
        //     return new Promise(function (resolve, reject) {
        //         $.get("", function (data, status) {
        //             if (status == 'success') {
        //                 resolve("P03 Success");
        //             } else {
        //                 reject("P03 Fail")
        //             }
        //         });
        //     });
        // }).then(function (data) {
        //     console.log(data);
        // }).catch(function (data) {
        //     console.log(data);
        // });

        async function ajaxGen() {
            let s01 = await new Promise(function (resolve, reject) {
                $.get("", function (data, status) {
                    if (status == 'success') {
                        resolve("P01 Success");
                    } else {
                        reject("P01 Fail")
                    }
                });
            });

            console.log(s01);

            let s02 = await new Promise(function (resolve, reject) {
                $.get("", function (data, status) {
                    if (status == 'success') {
                        resolve("P02 Success");
                    } else {
                        reject("P02 Fail")
                    }
                });
            });

            console.log(s02);

            let s03 = await new Promise(function (resolve, reject) {
                $.get("", function (data, status) {
                    if (status == 'success') {
                        resolve("P03 Success");
                    } else {
                        reject("P03 Fail")
                    }
                });
            });

            console.log(s03);

            return;
        }

        ajaxGen();

        console.log("Main Thread");
    })
</script>
</body>
</html>